﻿using Architecture.API.Application.Command.UserInfoRoleCommand;
using Architecture.Domain;
using Architecture.Domain.Service.UserInfoRoleServices;
using MediatR;

namespace Architecture.API.Application.CommandHandlers.UserInfoRoleHandler
{
    /// <summary>
    /// 用户角色添加命令处理器
    /// </summary>
    public class UserInfoRoleAddCommandHandler : IRequestHandler<UserInfoRoleAddCommand, int>
    {
        /// <summary>
        /// 用户角色服务
        /// </summary>
        private readonly IUserInfoRoleService _userInfoRoleService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="userInfoRoleService">用户角色服务</param>
        public UserInfoRoleAddCommandHandler(IUserInfoRoleService userInfoRoleService)
        {
            _userInfoRoleService = userInfoRoleService;
        }

        /// <summary>
        /// 用户角色添加命令处理
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="cancellationToken">取消标记</param>
        /// <returns>返回受影响的行数</returns>
        public async Task<int> Handle(UserInfoRoleAddCommand request, CancellationToken cancellationToken)
        {
            return await _userInfoRoleService.AddUserInfoRole(new AddUserInfoRole() { roleId=request.roleId,ids=request.ids } );
        }
    }
}
